#include "StdAfx.h"
#include "ReportGenerator.h"
#include "ReportGenerator/ReportGenerator.h"
#include "ReportGenerator/DrawGrid.h"

struct ReportGenerator::pimpl_t
{
	CReportGenerator m_Impl;
};

ReportGenerator::ReportGenerator(void):
pimpl_(new pimpl_t)
{
}

ReportGenerator::~ReportGenerator(void)
{
	delete pimpl_;
}

string ReportGenerator::GetReportname( void )
{
	CString str = pimpl_->m_Impl.GetReportname();
	return string(str);
}

void ReportGenerator::SetReportname( const char * value )
{
	pimpl_->m_Impl.SetReportname(CString(value));
}

bool ReportGenerator::SetReportfile( const char * filename )
{
	return pimpl_->m_Impl.SetReportfile(CString(filename));
}

bool ReportGenerator::Add( int field, const char * data )
{
    return pimpl_->m_Impl.Add(field,CString(data));
}

bool ReportGenerator::Add( const char * field, const char * data )
{
	return pimpl_->m_Impl.Add(CString(field),CString(data));
}

bool ReportGenerator::Add( const char * field, StringArray & data )
{
	CStringArray arr;

	for(size_t i=0; i<data.size(); i++){
		arr.Add(data[i].c_str());
	}

	return pimpl_->m_Impl.Add(CString(field),arr);
}

bool ReportGenerator::FillGrid( const char * field, int rows, int cols, const char * data /*= ""*/ )
{
	return pimpl_->m_Impl.FillGrid(field,rows,cols,data);
}

bool ReportGenerator::ReplaceCell( const char * field, int row, int col, const char * data )
{
	return pimpl_->m_Impl.FillGrid(field,row,col,data);
}

bool ReportGenerator::AddTemplate( const char * filename, int type /*= TEMPLATE_TYPE_SECTION */ )
{
	return pimpl_->m_Impl.AddTemplate(CString(filename),type);
}

void ReportGenerator::New( void )
{
	pimpl_->m_Impl.New();
}

void ReportGenerator::Clear( void )
{
	pimpl_->m_Impl.Clear();
}

void ReportGenerator::Print( HDC hdc )
{
	pimpl_->m_Impl.Print(CDC::FromHandle(hdc));
}

void ReportGenerator::PrintPage( HDC hdc, int page/*=0 */ )
{
	pimpl_->m_Impl.PrintPage(CDC::FromHandle(hdc),page);
}

int ReportGenerator::CalculatePages( void )
{
	return pimpl_->m_Impl.CalculatePages();
}

string ReportGenerator::GetErrorMessage( void )
{
	const CString & str = pimpl_->m_Impl.GetErrorMessage();
	return string(str.GetString());
}

int ReportGenerator::GetTemplateSize( int tplte )
{
	return pimpl_->m_Impl.GetTemplateSize(tplte);
}

string ReportGenerator::GetFieldName( int field, int tplate /*= 0 */ )
{
	CString str = pimpl_->m_Impl.GetFieldName(field,tplate);
	return string(str.GetString());
}

int ReportGenerator::GetFieldType( const char * field, int tplate /*= -1 */ )
{
	return pimpl_->m_Impl.GetFieldType(CString(field),tplate);
}

int ReportGenerator::GetFieldColumns( const char * field, int tplate /*= -1 */ )
{
	return pimpl_->m_Impl.GetFieldColumns(CString(field),tplate);
}

void ReportGenerator::ResizeField( const char * field )
{
	CDrawGrid * grid = dynamic_cast<CDrawGrid*>( pimpl_->m_Impl.GetObject( field ) );
	CDoubleRect drc = grid->GetPosition();
	int lines = grid->GetLines();
	int lpp = grid->GetLinesPerPage();
	int lpi = grid->GetLPI();
	int po = grid->GetPageOffset();
	int pages = grid->GetPages();
	//grid->SetPosition(drc;
}
